import { getMajorList } from "@/static/js/quiz.js";
export default {
  data() {
    return {
      expertList: [],
      userInfo: {},
      params: {
        page: 1,
        pagesize: 10,
      },
      listStatus: "noMore",
      isRefreshing: false, //界面下拉的状态
    };
  },
  onLoad() {
    this.getMajorList();
  },
  methods: {
    //去提问
    goAsk(item) {
      let token = uni.getStorageSync("token");
      if (!token) {
        uni.navigateTo({
          url: "/pages/login/login",
        });
        return;
      }
      let userInfo = uni.getStorageSync("userInfo");
      if (item.user_id == userInfo.id) {
        this.$tools.msg("您不能向自己提问");
        return;
      } else {
        uni.navigateTo({
          url: "/quiz/ask/index?id=" + item.user_id,
        });
      }
    },
    goHome(item) {
      let token = uni.getStorageSync("token");
      if (!token) {
        uni.navigateTo({
          url: "/pages/login/login",
        });
        return;
      }
      uni.navigateTo({
        url: "/pages/my/homeCenter/taTeacherHome?id=" + item.user_id,
      });
    },
    getMajorList() {
      this.listStatus = "loading";
      getMajorList(this.params).then((res) => {
        if (res.code == 1) {
          if (this.params.page == 1) {
            this.expertList = [];
          }
          let newList = res.data;
          this.listStatus = newList.length >= this.params.pagesize ? "more" : "noMore";
          this.expertList.push(...newList);
          this.isRefreshing = false;
        }
      });
    },
    //下拉刷新
    reload() {
      this.isRefreshing = true;
      this.params.page = 1;
      this.getMajorList();
    },

    loadMore() {
      if (this.listStatus == "more") {
        this.params.page += 1;
        this.getMajorList();
      }
    },
  },
};